export const stats = {
  namespaced: true,
  state: () => ({
    totalGames: 0,
    wins: 0,
    winRate: '0%',
    marblesOwned: 3, // 初始3个弹珠
    highestScore: 0,
    last10Games: []
  }),
  mutations: {
    updateStats(state, payload) {
      Object.assign(state, payload)
    },
    addGameRecord(state, record) {
      state.last10Games.unshift(record)
      if(state.last10Games.length > 10) {
        state.last10Games.pop()
      }
    }
  },
  actions: {
    async fetchStats({ commit }) {
      // Mock数据
      const mockData = {
        totalGames: 42,
        wins: 28,
        winRate: '66.7%',
        marblesOwned: 15,
        highestScore: 320,
        last10Games: [
          {result: 'win', score: 280, marblesChange: +1, date: '2025-03-28'},
          {result: 'lose', score: 150, marblesChange: -1, date: '2025-03-27'},
          // 其他8条记录...
        ]
      }
      commit('updateStats', mockData)
    }
  },
  getters: {
    formattedStats(state) {
      return {
        ...state,
        winCount: state.wins,
        loseCount: state.totalGames - state.wins
      }
    }
  }
}
